package kr.hkit.androidcomplete01.ch19;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class ThreadEx extends Activity {

	int mMainValue;
	int mBackValue;
	TextView mMainTv;
	TextView mBackTv;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch19_threadtest);
		mMainTv = (TextView) findViewById(R.id.mainvalue);
		mBackTv = (TextView) findViewById(R.id.backvalue);
		BackThread thread = new BackThread();
		thread.setDaemon(true);
		thread.start();
	}

	public void mOnClick(View v) {
		mMainValue++;
		mMainTv.setText("Main Value : " + mMainValue);
		mBackTv.setText("BackValue : " + mBackValue);
	}

	class BackThread extends Thread {
		public void run() {
			while (true) {
				mBackValue++;
				//mMainTv.setText("BackValue : " +mBackValue); 이거안됨
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					;
				}
			}
		}
	}
}
